from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *

class HbaseCommon():
    transport = TSocket.TSocket('analysis-02', 9090);
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport);
    client = Hbase.Client(protocol)
    transport.open()

    #获取一行的值
    def getrow(tableName,rowkey):
        result = HbaseCommon.client.getRow(tableName, rowkey)
        return result

    #添加值
    def addrow(tableName,rowkey,listcolumn):
        mutations=[]
        for i in listcolumn:
            mutations.append(Mutation(column=i[0], value=i[1]))
        # mutations = [Mutation(column="cf:a", value="1a")]
        HbaseCommon.client.mutateRow(tableName, rowkey, mutations)
        return "ok"




